<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-motormux.h</h1>  </div>
</div>
<div class="contents">
<a href="mindsensors-motormux_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup mindsensors</span>
<a name="l00002"></a>00002 <span class="comment"> * @{</span>
<a name="l00003"></a>00003 <span class="comment"> * @defgroup msmmux NXT Motor MUX</span>
<a name="l00004"></a>00004 <span class="comment"> * NXT Motor MUX</span>
<a name="l00005"></a>00005 <span class="comment"> * @{</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">/*</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: mindsensors-motormux.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef __MSMMUX_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define __MSMMUX_H__</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment">/** \file mindsensors-motormux.h</span>
<a name="l00015"></a>00015 <span class="comment"> * \brief Mindsensors Motor MUX driver</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * mindsensors-motormux.h provides an API for the Mindsensors Motor MUX.</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> * Changelog:</span>
<a name="l00020"></a>00020 <span class="comment"> * - 0.1: Initial release</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * Credits:</span>
<a name="l00023"></a>00023 <span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00028"></a>00028 <span class="comment"></span>
<a name="l00029"></a>00029 <span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<a name="l00030"></a>00030 <span class="comment"> * \date 05 April 2010</span>
<a name="l00031"></a>00031 <span class="comment"> * \version 0.1</span>
<a name="l00032"></a>00032 <span class="comment"> * \example mindsensors-motormux-test1.c</span>
<a name="l00033"></a>00033 <span class="comment"> * \example mindsensors-motormux-test2.c</span>
<a name="l00034"></a>00034 <span class="comment"> */</span>
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 <span class="preprocessor">#pragma systemFile</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>
<a name="l00042"></a>00042 <span class="preprocessor">#ifndef __MMUX_H__</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common-mmux_8h.html" title="Commonly used types and defines used by Motor MUX drivers.">common-MMUX.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#endif</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span>
<a name="l00046"></a><a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">00046</a> <span class="preprocessor">#define MSMMUX_I2C_ADDR         0x06  </span><span class="comment">/*!&lt; MSMMUX I2C device address */</span>
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="comment">// Motor control registers</span>
<a name="l00049"></a><a class="code" href="group__msmmux.html#gae48d4cff2c8ccdb011fa7b3aab523adf">00049</a> <span class="preprocessor">#define MSMMUX_REG_CMD          0x41  </span><span class="comment">/*!&lt; Command register */</span>
<a name="l00050"></a>00050 
<a name="l00051"></a><a class="code" href="group__msmmux.html#ga8c8b3af6beb087e1fd05d397b9b1ace5">00051</a> <span class="preprocessor">#define MSMMUX_MOT_OFFSET       0x42  </span><span class="comment">/*!&lt; Motor regiser offset */</span>
<a name="l00052"></a><a class="code" href="group__msmmux.html#gac650c60ed1552bdddb6c614558f9e5d0">00052</a> <span class="preprocessor">#define MSMMUX_TARG_ENC         0x00  </span><span class="comment">/*!&lt; Target encoder value */</span>
<a name="l00053"></a><a class="code" href="group__msmmux.html#ga095db3c1ca34b9d4e0fe49afe8bbc29e">00053</a> <span class="preprocessor">#define MSMMUX_POWER            0x04  </span><span class="comment">/*!&lt; Motor power */</span>
<a name="l00054"></a><a class="code" href="group__msmmux.html#gabee839cd65db79708af3e59d6c59d8dd">00054</a> <span class="preprocessor">#define MSMMUX_TARG_TIME        0x05  </span><span class="comment">/*!&lt; Time target value */</span>
<a name="l00055"></a><a class="code" href="group__msmmux.html#ga5befe114da7506da601ab2e1915d068d">00055</a> <span class="preprocessor">#define MSMMUX_CMD_B            0x06  </span><span class="comment">/*!&lt; Command B register - for future use */</span>
<a name="l00056"></a><a class="code" href="group__msmmux.html#ga0c726f775a3cd2d58bb52884974ae10a">00056</a> <span class="preprocessor">#define MSMMUX_CMD_A            0x07  </span><span class="comment">/*!&lt; Command A regiser */</span>
<a name="l00057"></a><a class="code" href="group__msmmux.html#ga3b917057a8f3ac8adf27bd90187b70fe">00057</a> <span class="preprocessor">#define MSMMUX_ENTRY_SIZE       0x08  </span><span class="comment">/*!&lt; Number of registers per motor channel */</span>
<a name="l00058"></a><a class="code" href="group__msmmux.html#gab490c7c21096313940d1d677e1f15d2b">00058</a> <span class="preprocessor">#define MSMMUX_TACHO_MOT1       0x62  </span><span class="comment">/*!&lt; Tacho count for motor 1 */</span>
<a name="l00059"></a><a class="code" href="group__msmmux.html#ga95108db52512c8783c4d75168a2fa5d6">00059</a> <span class="preprocessor">#define MSMMUX_TACHO_MOT2       0x66  </span><span class="comment">/*!&lt; Tacho count for motor 2 */</span>
<a name="l00060"></a><a class="code" href="group__msmmux.html#gab023b064da656ef35bdfb26a38c22a7f">00060</a> <span class="preprocessor">#define MSMMUX_STATUS_MOT1      0x72  </span><span class="comment">/*!&lt; Status for motor 1 */</span>
<a name="l00061"></a><a class="code" href="group__msmmux.html#ga86a9d90e1c78977bf3ee5583207cf52e">00061</a> <span class="preprocessor">#define MSMMUX_STATUS_MOT2      0x73  </span><span class="comment">/*!&lt; Status for motor 2 */</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">// PID registers</span>
<a name="l00064"></a><a class="code" href="group__msmmux.html#ga9be189f09f2e3f3416d7be23719df312">00064</a> <span class="preprocessor">#define MSMMUX_KP_TACHO         0x7A  </span><span class="comment">/*!&lt; Kp for Tachometer Position Control */</span>
<a name="l00065"></a><a class="code" href="group__msmmux.html#ga5f9f34c18af41d95b0e78c5fb600bec5">00065</a> <span class="preprocessor">#define MSMMUX_KI_TACHO         0x7C  </span><span class="comment">/*!&lt; Ki for Tachometer Position Control */</span>
<a name="l00066"></a><a class="code" href="group__msmmux.html#ga3ff39af77724326192176429074ceeff">00066</a> <span class="preprocessor">#define MSMMUX_KD_TACHO         0x7E  </span><span class="comment">/*!&lt; Kd for Tachometer Position Control */</span>
<a name="l00067"></a><a class="code" href="group__msmmux.html#ga688ad91d6a5f0ee13586e684e87ff694">00067</a> <span class="preprocessor">#define MSMMUX_KP_SPEED         0x80  </span><span class="comment">/*!&lt; Kp for Speed Control */</span>
<a name="l00068"></a><a class="code" href="group__msmmux.html#ga0cfed96ad8ef023bdaa88d7696b79f38">00068</a> <span class="preprocessor">#define MSMMUX_KI_SPEED         0x82  </span><span class="comment">/*!&lt; Ki for Speed Control */</span>
<a name="l00069"></a><a class="code" href="group__msmmux.html#ga5907ebc5382189cc9c06290a3b903fdb">00069</a> <span class="preprocessor">#define MSMMUX_KD_SPEED         0x84  </span><span class="comment">/*!&lt; Kd for Speed Control */</span>
<a name="l00070"></a><a class="code" href="group__msmmux.html#ga5094b753ed06a74097d1fc9d1abcbe9d">00070</a> <span class="preprocessor">#define MSMMUX_PASSCOUNT        0x86  </span><span class="comment">/*!&lt; Encoder count tolerance when motor is moving */</span>
<a name="l00071"></a><a class="code" href="group__msmmux.html#gad7ad488cba75aa97be2cc069cccf4bc9">00071</a> <span class="preprocessor">#define MSMMUX_TOLERANCE        0x87  </span><span class="comment">/*!&lt; Encoder count tolerance when motor is getting close to target */</span>
<a name="l00072"></a>00072 
<a name="l00073"></a>00073 <span class="comment">// Motor mode commands</span>
<a name="l00074"></a><a class="code" href="group__msmmux.html#gab8f60d07e59fd28326a70237f040b5f9">00074</a> <span class="preprocessor">#define MSMMUX_CMD_RESET_ALL    0x52  </span><span class="comment">/*!&lt; Reset the tachos and motor values */</span>
<a name="l00075"></a><a class="code" href="group__msmmux.html#ga97d0c3949df27605f6513dc97ea4a849">00075</a> <span class="preprocessor">#define MSMMUX_CMD_START_BOTH   0x53  </span><span class="comment">/*!&lt; Start both motors with parameters in motor registers */</span>
<a name="l00076"></a><a class="code" href="group__msmmux.html#ga1d305482996467216a57a6ea423120fa">00076</a> <span class="preprocessor">#define MSMMUX_CMD_FLOAT_MOT1   0x61  </span><span class="comment">/*!&lt; Stop motor 1 and allow to float */</span>
<a name="l00077"></a><a class="code" href="group__msmmux.html#ga73edefd7f959680dd295c60d4fefdf9c">00077</a> <span class="preprocessor">#define MSMMUX_CMD_FLOAT_MOT2   0x62  </span><span class="comment">/*!&lt; Stop motor 2 and allow to float */</span>
<a name="l00078"></a><a class="code" href="group__msmmux.html#gaf6be1bd3d07914c15eb391e03a1cb5f2">00078</a> <span class="preprocessor">#define MSMMUX_CMD_FLOAT_BOTH   0x63  </span><span class="comment">/*!&lt; Stop both motors and allow to float */</span>
<a name="l00079"></a><a class="code" href="group__msmmux.html#ga47a20b1c919909ae6a02143c9b38373e">00079</a> <span class="preprocessor">#define MSMMUX_CMD_BRAKE_MOT1   0x41  </span><span class="comment">/*!&lt; Stop motor 1 and brake */</span>
<a name="l00080"></a><a class="code" href="group__msmmux.html#ga3504e787d507d9728c02204693fa6feb">00080</a> <span class="preprocessor">#define MSMMUX_CMD_BRAKE_MOT2   0x42  </span><span class="comment">/*!&lt; Stop motor 2 and brake */</span>
<a name="l00081"></a><a class="code" href="group__msmmux.html#ga87fbc18bdfc214680a02d5a1d91c9e28">00081</a> <span class="preprocessor">#define MSMMUX_CMD_BRAKE_BOTH   0x43  </span><span class="comment">/*!&lt; Stop both motors and brake */</span>
<a name="l00082"></a><a class="code" href="group__msmmux.html#gaabb579aa54b2295b0b8edd49c2228efd">00082</a> <span class="preprocessor">#define MSMMUX_CMD_RESET_MOT1   0x72  </span><span class="comment">/*!&lt; Reset the encoder count for motor 1 */</span>
<a name="l00083"></a><a class="code" href="group__msmmux.html#ga881a7eba2dff7e0263b23debd48dab33">00083</a> <span class="preprocessor">#define MSMMUX_CMD_RESET_MOT2   0x73  </span><span class="comment">/*!&lt; Reset the encoder count for motor 2 */</span>
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 <span class="comment">// Motor status fields</span>
<a name="l00086"></a><a class="code" href="group__msmmux.html#ga0d86df0d411079268873cd4f536ab752">00086</a> <span class="preprocessor">#define MSMMUX_STAT_SPEED_CTRL  (0x01 &lt;&lt; 0) </span><span class="comment">/*!&lt; Motor is programmed to move at a fixed speed. */</span>
<a name="l00087"></a><a class="code" href="group__msmmux.html#gab9f7afb5cf501bed3383e2ccf2469edf">00087</a> <span class="preprocessor">#define MSMMUX_STAT_RAMPING     (0x01 &lt;&lt; 1) </span><span class="comment">/*!&lt; Motor is currently ramping up or down */</span>
<a name="l00088"></a><a class="code" href="group__msmmux.html#gae1fa3f26640f9a0436827f47a0bec0da">00088</a> <span class="preprocessor">#define MSMMUX_STAT_POWERED     (0x01 &lt;&lt; 2) </span><span class="comment">/*!&lt; Motor is powered, does not imply movement */</span>
<a name="l00089"></a><a class="code" href="group__msmmux.html#ga12a4f2918dcc985de13de95680a95145">00089</a> <span class="preprocessor">#define MSMMUX_STAT_POS_CTRL    (0x01 &lt;&lt; 3) </span><span class="comment">/*!&lt; Motor is either moving towards target or holding position. */</span>
<a name="l00090"></a><a class="code" href="group__msmmux.html#ga0ee62d545b2e35a86d625899b8eede39">00090</a> <span class="preprocessor">#define MSMMUX_STAT_BRAKED      (0x01 &lt;&lt; 4) </span><span class="comment">/*!&lt; Motor is braked.  0 means motor is floating */</span>
<a name="l00091"></a><a class="code" href="group__msmmux.html#ga4e5cf8d156b95e2e12e49fa9d04f51b2">00091</a> <span class="preprocessor">#define MSMMUX_STAT_OVERLOADED  (0x01 &lt;&lt; 5) </span><span class="comment">/*!&lt; Set to 1 when motor can&#39;t achieve desired speed */</span>
<a name="l00092"></a><a class="code" href="group__msmmux.html#gada8938c940c32aa849a08b1977459d99">00092</a> <span class="preprocessor">#define MSMMUX_STAT_TIMED       (0x01 &lt;&lt; 6) </span><span class="comment">/*!&lt; Motor is running for a specified duration */</span>
<a name="l00093"></a><a class="code" href="group__msmmux.html#ga4098a638a442daf317587ca49542dfd9">00093</a> <span class="preprocessor">#define MSMMUX_STAT_STALLED     (0x01 &lt;&lt; 7) </span><span class="comment">/*!&lt; Motor is stalled */</span>
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 <span class="comment">// commandA fields</span>
<a name="l00096"></a><a class="code" href="group__msmmux.html#gac26d3f74c8a080707ac5a440e609cbd5">00096</a> <span class="preprocessor">#define MSMMUX_CMD_SPEED        0x01  </span><span class="comment">/*!&lt; Speed control of your motor */</span>
<a name="l00097"></a><a class="code" href="group__msmmux.html#gab7630e78e2d1aec87172c53ab852e5dd">00097</a> <span class="preprocessor">#define MSMMUX_CMD_RAMP         0x02  </span><span class="comment">/*!&lt; Ramp the speed up or down */</span>
<a name="l00098"></a><a class="code" href="group__msmmux.html#ga6b41e450f882b087e0d473b530bad06a">00098</a> <span class="preprocessor">#define MSMMUX_CMD_RELATIVE     0x04  </span><span class="comment">/*!&lt; Make encoder target relative to current position */</span>
<a name="l00099"></a><a class="code" href="group__msmmux.html#ga445efda178d36ee108dcb4e7ba8871a6">00099</a> <span class="preprocessor">#define MSMMUX_CMD_TACHO        0x08  </span><span class="comment">/*!&lt; Use the encoder target to control motor */</span>
<a name="l00100"></a><a class="code" href="group__msmmux.html#gad80d4fd38ee9428cbae1fed2548b9118">00100</a> <span class="preprocessor">#define MSMMUX_CMD_BRK          0x10  </span><span class="comment">/*!&lt; Whether to brake (1) or float (0) when motor has reached its target */</span>
<a name="l00101"></a><a class="code" href="group__msmmux.html#ga27b2bd96842711a3bf879ae8ebfb2cff">00101</a> <span class="preprocessor">#define MSMMUX_CMD_HOLDPOS      0x20  </span><span class="comment">/*!&lt; Motor will hold position when this is enabled and push back when moved */</span>
<a name="l00102"></a><a class="code" href="group__msmmux.html#ga5d99484e4fbfc3f4aa3ccfb18ee384cb">00102</a> <span class="preprocessor">#define MSMMUX_CMD_TIME         0x40  </span><span class="comment">/*!&lt; Use the time target to control the motor */</span>
<a name="l00103"></a><a class="code" href="group__msmmux.html#ga54447c80943b69fca05e59963aeaede9">00103</a> <span class="preprocessor">#define MSMMUX_CMD_GO           0x80  </span><span class="comment">/*!&lt; Instruct the MUX to start the motors using the current registers */</span>
<a name="l00104"></a>00104 
<a name="l00105"></a><a class="code" href="group__msmmux.html#ga0d2f828e8c12510c8f5d1f794656bab0">00105</a> <span class="preprocessor">#define MSMMUX_RAMP_NONE        0x00  </span><span class="comment">/*!&lt; Use no ramping at all */</span>
<a name="l00106"></a><a class="code" href="group__msmmux.html#gaaeea706af7bf946b39cd6edbaf1f0749">00106</a> <span class="preprocessor">#define MSMMUX_RAMP_UP_DOWN     0x03  </span><span class="comment">/*!&lt; Use ramping to bring motor up to speed or to a halt */</span>
<a name="l00107"></a>00107 
<a name="l00108"></a><a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">00108</a> <span class="preprocessor">#define MSMMUX_ROT_UNLIMITED    0x00  </span><span class="comment">/*!&lt; Allow motor to rotate forever (or until batteries run out, of course) */</span>
<a name="l00109"></a><a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">00109</a> <span class="preprocessor">#define MSMMUX_ROT_DEGREES      0x01  </span><span class="comment">/*!&lt; Use encoder target to control motor (ie rotate motor X number of degrees) */</span>
<a name="l00110"></a>00110 <span class="comment">//#define MSMMUX_ROT_ROTATIONS    0x02</span>
<a name="l00111"></a><a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">00111</a> <span class="preprocessor">#define MSMMUX_ROT_SECONDS      0x03  </span><span class="comment">/*!&lt; Use time target to control motor (ie run for X seconds) */</span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00114"></a><a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">00114</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>;    <span class="comment">/*!&lt; Array to hold I2C command data */</span>
<a name="l00115"></a><a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">00115</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>;      <span class="comment">/*!&lt; Array to hold I2C reply data */</span>
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="comment">// Function prototypes</span>
<a name="l00118"></a>00118 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga70682f039e8bb97098baa6b1e2157693">MSMMUXinit</a>();
<a name="l00119"></a>00119 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga216466009d0c58c00d9bf9742493eaef">MSMMUXreadStatus</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte &amp;motorStatus);
<a name="l00120"></a>00120 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>(tSensors link, ubyte channel, <span class="keywordtype">long</span> setpoint, byte speed, ubyte seconds, ubyte commandA, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00121"></a>00121 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>(tSensors link, ubyte command, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00122"></a>00122 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gadfbbcac4655a147701f2731ed973e221">MSMMUXsetPID</a>(tSensors link, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kpTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kiTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kdTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kpSpeed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kiSpeed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kdSpeed, ubyte passCount, ubyte tolerance, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00123"></a>00123 <span class="comment">// bool MSMMUXsetPID(tSensors link, int kpTacho, int kiTacho, int kdTacho, int kpSpeed, int kiSpeed, int kdSpeed, ubyte passCount, ubyte tolerance, ubyte address = MSMMUX_I2C_ADDR);</span>
<a name="l00124"></a>00124 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga13f47f77e747922afe2434ce09710cf2">MSMMotor</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, byte power, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00125"></a>00125 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00126"></a>00126 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> brake, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00127"></a>00127 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga544a5e40fddec79252217f48fa0d1fe5">MSMMotorSetRotationTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>);
<a name="l00128"></a>00128 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#gae7941b243681d858ee5e3bd49407a0ed">MSMMotorSetTimeTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">int</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>);
<a name="l00129"></a>00129 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga450ae85721b1540e3f799d3845a45ce8">MSMMotorSetEncoderTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>);
<a name="l00130"></a>00130 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga450ae85721b1540e3f799d3845a45ce8">MSMMotorSetEncoderTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>, <span class="keywordtype">bool</span> relative);
<a name="l00131"></a>00131 <span class="keywordtype">long</span> <a class="code" href="group__msmmux.html#ga7b3fa7a33fc3e8ee6e2c9e8b10f7585d">MSMMotorEncoder</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00132"></a>00132 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5a3a1592dbfe977c68b7abed26595040">MSMMotorEncoderReset</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00133"></a>00133 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gadefafe924a76bce36240c7eb8fdbdf36">MSMMotorEncoderResetAll</a>(tSensors link, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00134"></a>00134 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga9f1fbe3a5ae946621e2316380c9881cf">MSMMotorBusy</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00135"></a>00135 <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gab9a66c248b3b369b26db9fd80f14b68c">MSMMotorStalled</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>);
<a name="l00136"></a>00136 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#gab74cc669bc4b1011e5ab6e36c8e5d0cb">MSMMotorSetBrake</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor);
<a name="l00137"></a>00137 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga118016629c8a58bec01143a437c2dfc6">MSMMotorSetFloat</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor);
<a name="l00138"></a>00138 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga0f61d2bd2faa6f654468c3bec21fc203">MSMMotorSetSpeedCtrl</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> constspeed);
<a name="l00139"></a>00139 <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga3415c02ea0ca9cf40c7585b8cb187a66">MSMMotorSetRamping</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> ramping);
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 <span class="comment">/*</span>
<a name="l00143"></a>00143 <span class="comment"> * Initialise the mmuxData array needed for keeping track of motor settings</span>
<a name="l00144"></a>00144 <span class="comment"> */</span>
<a name="l00145"></a><a class="code" href="group__msmmux.html#ga70682f039e8bb97098baa6b1e2157693">00145</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga70682f039e8bb97098baa6b1e2157693">MSMMUXinit</a>(){
<a name="l00146"></a>00146   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 4; i++) {
<a name="l00147"></a>00147     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].runToTarget[0], <span class="keyword">false</span>, 4);
<a name="l00148"></a>00148     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].brake[0], <span class="keyword">true</span>, 4);
<a name="l00149"></a>00149     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].pidcontrol[0], <span class="keyword">true</span>, 4);
<a name="l00150"></a>00150     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].<a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>[0], 0, 4*4);
<a name="l00151"></a>00151     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].ramping[0], <a class="code" href="group__msmmux.html#ga0d2f828e8c12510c8f5d1f794656bab0">MSMMUX_RAMP_NONE</a>, 4);
<a name="l00152"></a>00152     memset(<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].targetUnit[0], <a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">MSMMUX_ROT_UNLIMITED</a>, 4);
<a name="l00153"></a>00153     <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[i].<a class="code" href="structmmux_data_t.html#ad86e7ae1ce88f3a7655a02558318afc3">initialised</a> = <span class="keyword">true</span>;
<a name="l00154"></a>00154   }
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157 <span class="comment"></span>
<a name="l00158"></a>00158 <span class="comment">/**</span>
<a name="l00159"></a>00159 <span class="comment"> * Read the status byte of the specified motor</span>
<a name="l00160"></a>00160 <span class="comment"> *</span>
<a name="l00161"></a>00161 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00162"></a>00162 <span class="comment"> * @param motorStatus status of the motor</span>
<a name="l00163"></a>00163 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00164"></a>00164 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00165"></a>00165 <span class="comment"> */</span>
<a name="l00166"></a><a class="code" href="group__msmmux.html#ga26a5dc9dd5985e6567390d390badd936">00166</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga216466009d0c58c00d9bf9742493eaef">MSMMUXreadStatus</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte &amp;motorStatus, ubyte address) {
<a name="l00167"></a>00167 
<a name="l00168"></a>00168   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00169"></a>00169 
<a name="l00170"></a>00170   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 2;               <span class="comment">// Message size</span>
<a name="l00171"></a>00171   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = <a class="code" href="group__msmmux.html#ga2bbcbdd8012e4a24c5e4215523042a42">MSMMUX_I2C_ADDR</a>; <span class="comment">// I2C Address</span>
<a name="l00172"></a>00172 
<a name="l00173"></a>00173   <span class="keywordflow">switch</span> ((byte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)) {
<a name="l00174"></a>00174     <span class="keywordflow">case</span> 0: <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#gab023b064da656ef35bdfb26a38c22a7f">MSMMUX_STATUS_MOT1</a>; <span class="keywordflow">break</span>;
<a name="l00175"></a>00175     <span class="keywordflow">case</span> 1: <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#ga86a9d90e1c78977bf3ee5583207cf52e">MSMMUX_STATUS_MOT2</a>; <span class="keywordflow">break</span>;
<a name="l00176"></a>00176   }
<a name="l00177"></a>00177 
<a name="l00178"></a>00178   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>, 1))
<a name="l00179"></a>00179     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181   motorStatus = <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[0];
<a name="l00182"></a>00182 
<a name="l00183"></a>00183   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00184"></a>00184 }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186 <span class="comment"></span>
<a name="l00187"></a>00187 <span class="comment">/**</span>
<a name="l00188"></a>00188 <span class="comment"> * Send a command to the MMUX.</span>
<a name="l00189"></a>00189 <span class="comment"> *</span>
<a name="l00190"></a>00190 <span class="comment"> * Note: this is an internal function and shouldn&#39;t be used directly</span>
<a name="l00191"></a>00191 <span class="comment"> * @param link the MMUX port number</span>
<a name="l00192"></a>00192 <span class="comment"> * @param channel the channel the command should apply to</span>
<a name="l00193"></a>00193 <span class="comment"> * @param setpoint the encoder count the motor should move to</span>
<a name="l00194"></a>00194 <span class="comment"> * @param speed the speed the motor should move at</span>
<a name="l00195"></a>00195 <span class="comment"> * @param seconds the number of seconds the motor should run for.  Note that this takes precedence over the encoder target</span>
<a name="l00196"></a>00196 <span class="comment"> * @param commandA the command to be sent to the motor</span>
<a name="l00197"></a>00197 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00198"></a>00198 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00199"></a>00199 <span class="comment"> */</span>
<a name="l00200"></a><a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">00200</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>(tSensors link, ubyte channel, <span class="keywordtype">long</span> setpoint, byte speed, ubyte seconds, ubyte commandA, ubyte address) {
<a name="l00201"></a>00201   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00202"></a>00202 
<a name="l00203"></a>00203   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 10;               <span class="comment">// Message size</span>
<a name="l00204"></a>00204   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = address;          <span class="comment">// I2C Address</span>
<a name="l00205"></a>00205   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#ga8c8b3af6beb087e1fd05d397b9b1ace5">MSMMUX_MOT_OFFSET</a> + (channel * <a class="code" href="group__msmmux.html#ga3b917057a8f3ac8adf27bd90187b70fe">MSMMUX_ENTRY_SIZE</a>);
<a name="l00206"></a>00206   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[3] = (setpoint &gt;&gt;  0) &amp; 0xFF;
<a name="l00207"></a>00207   MSMMUX_I2CRequest[4] = (setpoint &gt;&gt;  8) &amp; 0xFF;
<a name="l00208"></a>00208   MSMMUX_I2CRequest[5] = (setpoint &gt;&gt; 16) &amp; 0xFF;
<a name="l00209"></a>00209   MSMMUX_I2CRequest[6] = (setpoint &gt;&gt; 24) &amp; 0xFF;
<a name="l00210"></a>00210   MSMMUX_I2CRequest[7] = (speed &amp; 0xFF);
<a name="l00211"></a>00211   MSMMUX_I2CRequest[8] = seconds;
<a name="l00212"></a>00212   MSMMUX_I2CRequest[9] = 0;
<a name="l00213"></a>00213   MSMMUX_I2CRequest[10] = commandA;
<a name="l00214"></a>00214 
<a name="l00215"></a>00215   <span class="comment">// make sure the targetUnit is reset for the next time</span>
<a name="l00216"></a>00216   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[link].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[channel] = <a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">MSMMUX_ROT_UNLIMITED</a>;
<a name="l00217"></a>00217 
<a name="l00218"></a>00218   <span class="comment">// send the command to the mmux</span>
<a name="l00219"></a>00219   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, MSMMUX_I2CRequest);
<a name="l00220"></a>00220 
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223 <span class="comment"></span>
<a name="l00224"></a>00224 <span class="comment">/**</span>
<a name="l00225"></a>00225 <span class="comment"> * Send a command to the MMUX.</span>
<a name="l00226"></a>00226 <span class="comment"> *</span>
<a name="l00227"></a>00227 <span class="comment"> * Note: this is an internal function and shouldn&#39;t be used directly</span>
<a name="l00228"></a>00228 <span class="comment"> * @param link the MMUX port number</span>
<a name="l00229"></a>00229 <span class="comment"> * @param command the command to be sent to the motor</span>
<a name="l00230"></a>00230 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00231"></a>00231 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00232"></a>00232 <span class="comment"> */</span>
<a name="l00233"></a><a class="code" href="group__msmmux.html#ga07e800b628b5f9a5fa6716671fb906ab">00233</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>(tSensors link, ubyte command, ubyte address) {
<a name="l00234"></a>00234   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00235"></a>00235 
<a name="l00236"></a>00236   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 3;               <span class="comment">// Message size</span>
<a name="l00237"></a>00237   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = address; <span class="comment">// I2C Address</span>
<a name="l00238"></a>00238   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#gae48d4cff2c8ccdb011fa7b3aab523adf">MSMMUX_REG_CMD</a>;
<a name="l00239"></a>00239   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[3] = command;
<a name="l00240"></a>00240 
<a name="l00241"></a>00241   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>);
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 <span class="comment"></span>
<a name="l00245"></a>00245 <span class="comment">/**</span>
<a name="l00246"></a>00246 <span class="comment"> * Configure the internal PID controller.  Tweaking these values will change the</span>
<a name="l00247"></a>00247 <span class="comment"> * behaviour of the motors, how they approach their target, how they maintain speed, etc.</span>
<a name="l00248"></a>00248 <span class="comment"> * These settings do not persist, disconnecting the MUX will reset these values to their</span>
<a name="l00249"></a>00249 <span class="comment"> * defaults.  These settings are MUX-wide, so will apply to how BOTH motors are controlled.</span>
<a name="l00250"></a>00250 <span class="comment"> *</span>
<a name="l00251"></a>00251 <span class="comment"> * Please refer to the User Guide for more detailed information on how these parameters</span>
<a name="l00252"></a>00252 <span class="comment"> * should be used.</span>
<a name="l00253"></a>00253 <span class="comment"> *</span>
<a name="l00254"></a>00254 <span class="comment"> * @param link the MMUX port number</span>
<a name="l00255"></a>00255 <span class="comment"> * @param kpTacho Kp for Tachometer Position Control</span>
<a name="l00256"></a>00256 <span class="comment"> * @param kiTacho Ki for Tachometer Position Control</span>
<a name="l00257"></a>00257 <span class="comment"> * @param kdTacho Kd for Tachometer Position Control</span>
<a name="l00258"></a>00258 <span class="comment"> * @param kpSpeed Kp for Speed Control</span>
<a name="l00259"></a>00259 <span class="comment"> * @param kiSpeed Ki for Speed Control</span>
<a name="l00260"></a>00260 <span class="comment"> * @param kdSpeed Kd for Speed Control</span>
<a name="l00261"></a>00261 <span class="comment"> * @param passCount Encoder count tolerance when motor is moving</span>
<a name="l00262"></a>00262 <span class="comment"> * @param tolerance Encoder count tolerance when motor is getting close to target</span>
<a name="l00263"></a>00263 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00264"></a>00264 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00265"></a>00265 <span class="comment"> */</span>
<a name="l00266"></a><a class="code" href="group__msmmux.html#gadfbbcac4655a147701f2731ed973e221">00266</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gadfbbcac4655a147701f2731ed973e221">MSMMUXsetPID</a>(tSensors link, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kpTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kiTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kdTacho, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kpSpeed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kiSpeed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> kdSpeed, ubyte passCount, ubyte tolerance, ubyte address) {
<a name="l00267"></a>00267   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00268"></a>00268 
<a name="l00269"></a>00269   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 16;               <span class="comment">// Message size</span>
<a name="l00270"></a>00270   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = address; <span class="comment">// I2C Address</span>
<a name="l00271"></a>00271   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#ga9be189f09f2e3f3416d7be23719df312">MSMMUX_KP_TACHO</a>;
<a name="l00272"></a>00272   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[3] = kpTacho &amp; 0xFF;
<a name="l00273"></a>00273   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[4] = (kpTacho &gt;&gt; 8) &amp; 0xFF;
<a name="l00274"></a>00274   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[5] = kiTacho &amp; 0xFF;
<a name="l00275"></a>00275   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[6] = (kiTacho &gt;&gt; 8) &amp; 0xFF;
<a name="l00276"></a>00276   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[7] = kdTacho &amp; 0xFF;
<a name="l00277"></a>00277   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[8] = (kdTacho &gt;&gt; 8) &amp; 0xFF;
<a name="l00278"></a>00278   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[9] = kpSpeed &amp; 0xFF;
<a name="l00279"></a>00279   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[10] = (kpSpeed &gt;&gt; 8) &amp; 0xFF;
<a name="l00280"></a>00280   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[11] = kiSpeed &amp; 0xFF;
<a name="l00281"></a>00281   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[12] = (kiSpeed &gt;&gt; 8) &amp; 0xFF;
<a name="l00282"></a>00282   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[13] = kdSpeed &amp; 0xFF;
<a name="l00283"></a>00283   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[14] = (kdSpeed &gt;&gt; 8) &amp; 0xFF;
<a name="l00284"></a>00284   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[15] = passCount;
<a name="l00285"></a>00285   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[16] = tolerance;
<a name="l00286"></a>00286 
<a name="l00287"></a>00287   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>);
<a name="l00288"></a>00288 }
<a name="l00289"></a>00289 
<a name="l00290"></a>00290 <span class="comment"></span>
<a name="l00291"></a>00291 <span class="comment">/**</span>
<a name="l00292"></a>00292 <span class="comment"> * Run motor with specified speed.</span>
<a name="l00293"></a>00293 <span class="comment"> *</span>
<a name="l00294"></a>00294 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00295"></a>00295 <span class="comment"> * @param power power the amount of power to apply to the motor, value between -100 and +100</span>
<a name="l00296"></a>00296 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00297"></a>00297 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00298"></a>00298 <span class="comment"> */</span>
<a name="l00299"></a><a class="code" href="group__msmmux.html#ga13f47f77e747922afe2434ce09710cf2">00299</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga13f47f77e747922afe2434ce09710cf2">MSMMotor</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, byte power, ubyte address) {
<a name="l00300"></a>00300   ubyte commandA = 0;
<a name="l00301"></a>00301   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a201498569375a319530e44ca4bc069ff">pidcontrol</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)]) ? <a class="code" href="group__msmmux.html#gac26d3f74c8a080707ac5a440e609cbd5">MSMMUX_CMD_SPEED</a> : 0;
<a name="l00302"></a>00302   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#aaf32ec57dafc672cd270aeaceab02bdb">ramping</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] != <a class="code" href="group__msmmux.html#ga0d2f828e8c12510c8f5d1f794656bab0">MSMMUX_RAMP_NONE</a>) ? <a class="code" href="group__msmmux.html#gab7630e78e2d1aec87172c53ab852e5dd">MSMMUX_CMD_RAMP</a> : 0;
<a name="l00303"></a>00303   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a9063971c953b64e1b32222b9ce5780f6">brake</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)]) ? <a class="code" href="group__msmmux.html#gad80d4fd38ee9428cbae1fed2548b9118">MSMMUX_CMD_BRK</a> : 0;
<a name="l00304"></a>00304   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] == <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>) ? <a class="code" href="group__msmmux.html#ga445efda178d36ee108dcb4e7ba8871a6">MSMMUX_CMD_TACHO</a> : 0;
<a name="l00305"></a>00305   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] == <a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">MSMMUX_ROT_SECONDS</a>) ? <a class="code" href="group__msmmux.html#ga5d99484e4fbfc3f4aa3ccfb18ee384cb">MSMMUX_CMD_TIME</a> : 0;
<a name="l00306"></a>00306   commandA += (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a50271be624f6c46183c5b1c50973ea14">relTarget</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)]) ? <a class="code" href="group__msmmux.html#ga6b41e450f882b087e0d473b530bad06a">MSMMUX_CMD_RELATIVE</a> : 0;
<a name="l00307"></a>00307   commandA += <a class="code" href="group__msmmux.html#ga54447c80943b69fca05e59963aeaede9">MSMMUX_CMD_GO</a>;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   <span class="keywordflow">switch</span> (<a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)]) {
<a name="l00310"></a>00310     <span class="keywordflow">case</span> <a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">MSMMUX_ROT_UNLIMITED</a>: <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), (ubyte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor), 0, power, 0, commandA, address);
<a name="l00311"></a>00311     <span class="keywordflow">case</span> <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>:   <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), (ubyte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor), <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)], power, 0, commandA, address);
<a name="l00312"></a>00312     <span class="keywordflow">case</span> <a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">MSMMUX_ROT_SECONDS</a>:   <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), (ubyte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor), 0, power, <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)], commandA, address);
<a name="l00313"></a>00313   }
<a name="l00314"></a>00314   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00315"></a>00315 }
<a name="l00316"></a>00316 
<a name="l00317"></a>00317 <span class="comment"></span>
<a name="l00318"></a>00318 <span class="comment">/**</span>
<a name="l00319"></a>00319 <span class="comment"> * Stop the motor. Uses the brake method specified with MSMMotorSetBrake or MSMMotorSetFloat.</span>
<a name="l00320"></a>00320 <span class="comment"> * The default is to use braking.</span>
<a name="l00321"></a>00321 <span class="comment"> *</span>
<a name="l00322"></a>00322 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00323"></a>00323 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00324"></a>00324 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00325"></a>00325 <span class="comment"> */</span>
<a name="l00326"></a><a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">00326</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address) {
<a name="l00327"></a>00327   <span class="keywordflow">if</span> (<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor) == 0)
<a name="l00328"></a>00328     <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(muxmotor, <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].brake[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)], address);
<a name="l00329"></a>00329   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor) == 1)
<a name="l00330"></a>00330     <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(muxmotor, <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].brake[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)], address);
<a name="l00331"></a>00331   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00332"></a>00332 }
<a name="l00333"></a>00333 
<a name="l00334"></a>00334 <span class="comment"></span>
<a name="l00335"></a>00335 <span class="comment">/**</span>
<a name="l00336"></a>00336 <span class="comment"> * Stop the motor. This function overrides the preconfigured braking method.</span>
<a name="l00337"></a>00337 <span class="comment"> *</span>
<a name="l00338"></a>00338 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00339"></a>00339 <span class="comment"> * @param brake when set to true: use brake, false: use float</span>
<a name="l00340"></a>00340 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00341"></a>00341 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00342"></a>00342 <span class="comment"> */</span>
<a name="l00343"></a><a class="code" href="group__msmmux.html#ga7e618ec49817ea3d395cffbc0abdfd17">00343</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5c6f609cbb6a314fd9b25fb8376590dd">MSMotorStop</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> brake, ubyte address) {
<a name="l00344"></a>00344   <span class="keywordflow">if</span> (<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor) == 0)
<a name="l00345"></a>00345     <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), brake ? <a class="code" href="group__msmmux.html#ga47a20b1c919909ae6a02143c9b38373e">MSMMUX_CMD_BRAKE_MOT1</a> : <a class="code" href="group__msmmux.html#ga1d305482996467216a57a6ea423120fa">MSMMUX_CMD_FLOAT_MOT1</a>, address);
<a name="l00346"></a>00346   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor) == 1)
<a name="l00347"></a>00347     <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), brake ? <a class="code" href="group__msmmux.html#ga3504e787d507d9728c02204693fa6feb">MSMMUX_CMD_BRAKE_MOT2</a> : <a class="code" href="group__msmmux.html#ga73edefd7f959680dd295c60d4fefdf9c">MSMMUX_CMD_FLOAT_MOT2</a>, address);
<a name="l00348"></a>00348   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00349"></a>00349 }
<a name="l00350"></a>00350 
<a name="l00351"></a>00351 <span class="comment"></span>
<a name="l00352"></a>00352 <span class="comment">/**</span>
<a name="l00353"></a>00353 <span class="comment"> * Set rotation target for specified mux motor.</span>
<a name="l00354"></a>00354 <span class="comment"> *</span>
<a name="l00355"></a>00355 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00356"></a>00356 <span class="comment"> * @param target the rotation target value</span>
<a name="l00357"></a>00357 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00358"></a>00358 <span class="comment"> */</span>
<a name="l00359"></a><a class="code" href="group__msmmux.html#ga544a5e40fddec79252217f48fa0d1fe5">00359</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga544a5e40fddec79252217f48fa0d1fe5">MSMMotorSetRotationTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>) {
<a name="l00360"></a>00360   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a323674818d85ef4c3430253aa45a0d8e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = target * 360;
<a name="l00361"></a>00361   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>;
<a name="l00362"></a>00362 }
<a name="l00363"></a>00363 
<a name="l00364"></a>00364 <span class="comment"></span>
<a name="l00365"></a>00365 <span class="comment">/**</span>
<a name="l00366"></a>00366 <span class="comment"> * Set time target for specified mux motor. Seconds can be specified in</span>
<a name="l00367"></a>00367 <span class="comment"> * increments of 1 second with an upper limit of 255 seconds.</span>
<a name="l00368"></a>00368 <span class="comment"> *</span>
<a name="l00369"></a>00369 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00370"></a>00370 <span class="comment"> * @param target the time target value in seconds [1-255]</span>
<a name="l00371"></a>00371 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00372"></a>00372 <span class="comment"> */</span>
<a name="l00373"></a><a class="code" href="group__msmmux.html#gae7941b243681d858ee5e3bd49407a0ed">00373</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#gae7941b243681d858ee5e3bd49407a0ed">MSMMotorSetTimeTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">int</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>) {
<a name="l00374"></a>00374   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a323674818d85ef4c3430253aa45a0d8e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>;
<a name="l00375"></a>00375   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">MSMMUX_ROT_SECONDS</a>;
<a name="l00376"></a>00376 }
<a name="l00377"></a>00377 
<a name="l00378"></a>00378 <span class="comment"></span>
<a name="l00379"></a>00379 <span class="comment">/**</span>
<a name="l00380"></a>00380 <span class="comment"> * Set encoder target for specified mux motor.  Target is relative to current position.</span>
<a name="l00381"></a>00381 <span class="comment"> *</span>
<a name="l00382"></a>00382 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00383"></a>00383 <span class="comment"> * @param target the encoder target value in degrees.</span>
<a name="l00384"></a>00384 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00385"></a>00385 <span class="comment"> */</span>
<a name="l00386"></a><a class="code" href="group__msmmux.html#ga450ae85721b1540e3f799d3845a45ce8">00386</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga450ae85721b1540e3f799d3845a45ce8">MSMMotorSetEncoderTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>) {
<a name="l00387"></a>00387   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a323674818d85ef4c3430253aa45a0d8e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>;
<a name="l00388"></a>00388   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>;
<a name="l00389"></a>00389   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a50271be624f6c46183c5b1c50973ea14">relTarget</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <span class="keyword">true</span>;
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391 
<a name="l00392"></a>00392 <span class="comment"></span>
<a name="l00393"></a>00393 <span class="comment">/**</span>
<a name="l00394"></a>00394 <span class="comment"> * Set encoder target for specified mux motor.</span>
<a name="l00395"></a>00395 <span class="comment"> *</span>
<a name="l00396"></a>00396 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00397"></a>00397 <span class="comment"> * @param target the encoder target value in degrees.</span>
<a name="l00398"></a>00398 <span class="comment"> * @param relative specified target is relative to current position.</span>
<a name="l00399"></a>00399 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00400"></a>00400 <span class="comment"> */</span>
<a name="l00401"></a><a class="code" href="group__msmmux.html#ga9c3a8a71c81dd7a02f9936d222e5427d">00401</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga450ae85721b1540e3f799d3845a45ce8">MSMMotorSetEncoderTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">long</span> <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>, <span class="keywordtype">bool</span> relative) {
<a name="l00402"></a>00402   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a323674818d85ef4c3430253aa45a0d8e">target</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__htmc.html#ga39e0493ce40209f8833cc55adbeed48e">target</a>;
<a name="l00403"></a>00403   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#af605cf5944be1527f218146e36f01c7b">targetUnit</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>;
<a name="l00404"></a>00404   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a50271be624f6c46183c5b1c50973ea14">relTarget</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = relative;
<a name="l00405"></a>00405 }
<a name="l00406"></a>00406 
<a name="l00407"></a>00407 <span class="comment"></span>
<a name="l00408"></a>00408 <span class="comment">/**</span>
<a name="l00409"></a>00409 <span class="comment"> * Fetch the current encoder value for specified motor channel</span>
<a name="l00410"></a>00410 <span class="comment"> *</span>
<a name="l00411"></a>00411 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00412"></a>00412 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00413"></a>00413 <span class="comment"> * @return the current value of the encoder</span>
<a name="l00414"></a>00414 <span class="comment"> */</span>
<a name="l00415"></a><a class="code" href="group__msmmux.html#ga7b3fa7a33fc3e8ee6e2c9e8b10f7585d">00415</a> <span class="keywordtype">long</span> <a class="code" href="group__msmmux.html#ga7b3fa7a33fc3e8ee6e2c9e8b10f7585d">MSMMotorEncoder</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address) {
<a name="l00416"></a>00416   <span class="keywordtype">long</span> result;
<a name="l00417"></a>00417 
<a name="l00418"></a>00418   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00419"></a>00419 
<a name="l00420"></a>00420   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 2;               <span class="comment">// Message size</span>
<a name="l00421"></a>00421   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = address; <span class="comment">// I2C Address</span>
<a name="l00422"></a>00422 
<a name="l00423"></a>00423   <span class="keywordflow">switch</span> ((byte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)) {
<a name="l00424"></a>00424     <span class="keywordflow">case</span> 0: <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#gab490c7c21096313940d1d677e1f15d2b">MSMMUX_TACHO_MOT1</a>; <span class="keywordflow">break</span>;
<a name="l00425"></a>00425     <span class="keywordflow">case</span> 1: <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#ga95108db52512c8783c4d75168a2fa5d6">MSMMUX_TACHO_MOT2</a>; <span class="keywordflow">break</span>;
<a name="l00426"></a>00426   }
<a name="l00427"></a>00427 
<a name="l00428"></a>00428   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>,  <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>, 4))
<a name="l00429"></a>00429     <span class="keywordflow">return</span> 0;
<a name="l00430"></a>00430 
<a name="l00431"></a>00431   result = <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[0] + (<a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[1]&lt;&lt;8) + (<a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[2]&lt;&lt;16) + (<a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[3]&lt;&lt;24);
<a name="l00432"></a>00432 
<a name="l00433"></a>00433   <span class="keywordflow">return</span> result;
<a name="l00434"></a>00434 }
<a name="l00435"></a>00435 
<a name="l00436"></a>00436 <span class="comment"></span>
<a name="l00437"></a>00437 <span class="comment">/**</span>
<a name="l00438"></a>00438 <span class="comment"> * Reset target encoder for specified motor channel, use only at</span>
<a name="l00439"></a>00439 <span class="comment"> * the start of your program.  If you are using the standard NXT wheels</span>
<a name="l00440"></a>00440 <span class="comment"> * you will not run into problems with a wrap-around for the first 500kms</span>
<a name="l00441"></a>00441 <span class="comment"> * or so.</span>
<a name="l00442"></a>00442 <span class="comment"> *</span>
<a name="l00443"></a>00443 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00444"></a>00444 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00445"></a>00445 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00446"></a>00446 <span class="comment"> */</span>
<a name="l00447"></a>00447 
<a name="l00448"></a><a class="code" href="group__msmmux.html#ga5a3a1592dbfe977c68b7abed26595040">00448</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga5a3a1592dbfe977c68b7abed26595040">MSMMotorEncoderReset</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address) {
<a name="l00449"></a>00449   <span class="keywordflow">switch</span>((byte)<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)) {
<a name="l00450"></a>00450     <span class="keywordflow">case</span> 0: <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), <a class="code" href="group__msmmux.html#gaabb579aa54b2295b0b8edd49c2228efd">MSMMUX_CMD_RESET_MOT1</a>, address); <span class="keywordflow">break</span>;
<a name="l00451"></a>00451     <span class="keywordflow">case</span> 1: <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), <a class="code" href="group__msmmux.html#ga881a7eba2dff7e0263b23debd48dab33">MSMMUX_CMD_RESET_MOT2</a>, address); <span class="keywordflow">break</span>;
<a name="l00452"></a>00452   }
<a name="l00453"></a>00453   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00454"></a>00454 }
<a name="l00455"></a>00455 
<a name="l00456"></a>00456 <span class="comment"></span>
<a name="l00457"></a>00457 <span class="comment">/**</span>
<a name="l00458"></a>00458 <span class="comment"> * Reset all encoders on the specified motor-MUX. Use only at</span>
<a name="l00459"></a>00459 <span class="comment"> * the start of your program.  If you are using the standard NXT wheels</span>
<a name="l00460"></a>00460 <span class="comment"> * you will not run into problems with a wrap-around for the first 500kms</span>
<a name="l00461"></a>00461 <span class="comment"> * or so.</span>
<a name="l00462"></a>00462 <span class="comment"> *</span>
<a name="l00463"></a>00463 <span class="comment"> * @param link the MMUX port number</span>
<a name="l00464"></a>00464 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00465"></a>00465 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00466"></a>00466 <span class="comment"> */</span>
<a name="l00467"></a><a class="code" href="group__msmmux.html#gadefafe924a76bce36240c7eb8fdbdf36">00467</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gadefafe924a76bce36240c7eb8fdbdf36">MSMMotorEncoderResetAll</a>(tSensors link, ubyte address) {
<a name="l00468"></a>00468   <span class="keywordflow">return</span> <a class="code" href="group__msmmux.html#ga00149c5cea8e74fcc6dabb85d7ee7da6">MSMMUXsendCommand</a>(link, <a class="code" href="group__msmmux.html#gab8f60d07e59fd28326a70237f040b5f9">MSMMUX_CMD_RESET_ALL</a>, address);
<a name="l00469"></a>00469 }
<a name="l00470"></a>00470 
<a name="l00471"></a>00471 <span class="comment"></span>
<a name="l00472"></a>00472 <span class="comment">/**</span>
<a name="l00473"></a>00473 <span class="comment"> * Check if the specified motor is running or not.</span>
<a name="l00474"></a>00474 <span class="comment"> *</span>
<a name="l00475"></a>00475 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00476"></a>00476 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00477"></a>00477 <span class="comment"> * @return true if the motor is still running, false if it&#39;s idle</span>
<a name="l00478"></a>00478 <span class="comment"> */</span>
<a name="l00479"></a><a class="code" href="group__msmmux.html#ga9f1fbe3a5ae946621e2316380c9881cf">00479</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#ga9f1fbe3a5ae946621e2316380c9881cf">MSMMotorBusy</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address) {
<a name="l00480"></a>00480   ubyte status = 0;
<a name="l00481"></a>00481   ubyte commandA = 0;
<a name="l00482"></a>00482 
<a name="l00483"></a>00483   <span class="comment">// Fetch the last sent commandA</span>
<a name="l00484"></a>00484   memset(<a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a>));
<a name="l00485"></a>00485 
<a name="l00486"></a>00486   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[0] = 2;               <span class="comment">// Message size</span>
<a name="l00487"></a>00487   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[1] = address; <span class="comment">// I2C Address</span>
<a name="l00488"></a>00488   <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>[2] = <a class="code" href="group__msmmux.html#ga8c8b3af6beb087e1fd05d397b9b1ace5">MSMMUX_MOT_OFFSET</a> + (<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor) * <a class="code" href="group__msmmux.html#ga3b917057a8f3ac8adf27bd90187b70fe">MSMMUX_ENTRY_SIZE</a>) + <a class="code" href="group__msmmux.html#ga0c726f775a3cd2d58bb52884974ae10a">MSMMUX_CMD_A</a>;
<a name="l00489"></a>00489 
<a name="l00490"></a>00490   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>((tSensors)<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor), <a class="code" href="group__msmmux.html#ga2615cd4aad0f3cae15af8f3c817d6447">MSMMUX_I2CRequest</a>, <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>, 1))
<a name="l00491"></a>00491     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00492"></a>00492 
<a name="l00493"></a>00493   commandA = <a class="code" href="group__msmmux.html#ga2076a32842f8fffa2e42f3220c7db298">MSMMUX_I2CReply</a>[0];
<a name="l00494"></a>00494 
<a name="l00495"></a>00495   <span class="comment">// If commandA is 0 then the motor can&#39;t be busy.</span>
<a name="l00496"></a>00496   <span class="keywordflow">if</span> (commandA == 0)
<a name="l00497"></a>00497     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00498"></a>00498 
<a name="l00499"></a>00499   <span class="keywordflow">if</span> (!<a class="code" href="group__msmmux.html#ga216466009d0c58c00d9bf9742493eaef">MSMMUXreadStatus</a>(muxmotor, status, address))
<a name="l00500"></a>00500     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00501"></a>00501 
<a name="l00502"></a>00502   <span class="keywordflow">if</span> ((commandA &amp; <a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">MSMMUX_ROT_UNLIMITED</a>) == <a class="code" href="group__msmmux.html#ga270e6656167e1373376d46f0e222d62a">MSMMUX_ROT_UNLIMITED</a>)
<a name="l00503"></a>00503     <span class="keywordflow">return</span> ((status &amp; <a class="code" href="group__msmmux.html#gae1fa3f26640f9a0436827f47a0bec0da">MSMMUX_STAT_POWERED</a>) != 0);
<a name="l00504"></a>00504   <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((commandA &amp; <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>) == <a class="code" href="group__msmmux.html#ga14a10807e91a25ad983d53e6bd7c4dce">MSMMUX_ROT_DEGREES</a>)
<a name="l00505"></a>00505     <span class="keywordflow">return</span> ((status &amp; <a class="code" href="group__msmmux.html#ga12a4f2918dcc985de13de95680a95145">MSMMUX_STAT_POS_CTRL</a>) != 0);
<a name="l00506"></a>00506   <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((commandA &amp; <a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">MSMMUX_ROT_SECONDS</a>) == <a class="code" href="group__msmmux.html#gad71ab84a3f95e79d10c4272107c7ba4b">MSMMUX_ROT_SECONDS</a>)
<a name="l00507"></a>00507     <span class="keywordflow">return</span> ((status &amp; <a class="code" href="group__msmmux.html#gada8938c940c32aa849a08b1977459d99">MSMMUX_STAT_TIMED</a>) != 0);
<a name="l00508"></a>00508 
<a name="l00509"></a>00509   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00510"></a>00510 }
<a name="l00511"></a>00511 
<a name="l00512"></a>00512 <span class="comment"></span>
<a name="l00513"></a>00513 <span class="comment">/**</span>
<a name="l00514"></a>00514 <span class="comment"> * Check if the specified motor is running or not.</span>
<a name="l00515"></a>00515 <span class="comment"> *</span>
<a name="l00516"></a>00516 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00517"></a>00517 <span class="comment"> * @param address I2C address of the sensor (optional)</span>
<a name="l00518"></a>00518 <span class="comment"> * @return true if the motor is still running, false if it&#39;s idle</span>
<a name="l00519"></a>00519 <span class="comment"> */</span>
<a name="l00520"></a><a class="code" href="group__msmmux.html#gab9a66c248b3b369b26db9fd80f14b68c">00520</a> <span class="keywordtype">bool</span> <a class="code" href="group__msmmux.html#gab9a66c248b3b369b26db9fd80f14b68c">MSMMotorStalled</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, ubyte address) {
<a name="l00521"></a>00521   ubyte status = 0;
<a name="l00522"></a>00522   <span class="keywordflow">if</span> (!<a class="code" href="group__msmmux.html#ga216466009d0c58c00d9bf9742493eaef">MSMMUXreadStatus</a>(muxmotor, status, address))
<a name="l00523"></a>00523     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00524"></a>00524 
<a name="l00525"></a>00525   <span class="keywordflow">return</span> ((status &amp; <a class="code" href="group__msmmux.html#ga4098a638a442daf317587ca49542dfd9">MSMMUX_STAT_STALLED</a>) != 0);
<a name="l00526"></a>00526 }
<a name="l00527"></a>00527 
<a name="l00528"></a>00528 <span class="comment"></span>
<a name="l00529"></a>00529 <span class="comment">/**</span>
<a name="l00530"></a>00530 <span class="comment"> * Set the stopping method for the specified motor to brake.</span>
<a name="l00531"></a>00531 <span class="comment"> *</span>
<a name="l00532"></a>00532 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00533"></a>00533 <span class="comment"> */</span>
<a name="l00534"></a><a class="code" href="group__msmmux.html#gab74cc669bc4b1011e5ab6e36c8e5d0cb">00534</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#gab74cc669bc4b1011e5ab6e36c8e5d0cb">MSMMotorSetBrake</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor) {
<a name="l00535"></a>00535   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a9063971c953b64e1b32222b9ce5780f6">brake</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <span class="keyword">true</span>;
<a name="l00536"></a>00536 }
<a name="l00537"></a>00537 
<a name="l00538"></a>00538 <span class="comment"></span>
<a name="l00539"></a>00539 <span class="comment">/**</span>
<a name="l00540"></a>00540 <span class="comment"> * Set the stopping method for the specified motor to float.</span>
<a name="l00541"></a>00541 <span class="comment"> *</span>
<a name="l00542"></a>00542 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00543"></a>00543 <span class="comment"> */</span>
<a name="l00544"></a><a class="code" href="group__msmmux.html#ga118016629c8a58bec01143a437c2dfc6">00544</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga118016629c8a58bec01143a437c2dfc6">MSMMotorSetFloat</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor) {
<a name="l00545"></a>00545   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a9063971c953b64e1b32222b9ce5780f6">brake</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <span class="keyword">false</span>;
<a name="l00546"></a>00546 }
<a name="l00547"></a>00547 
<a name="l00548"></a>00548 <span class="comment"></span>
<a name="l00549"></a>00549 <span class="comment">/**</span>
<a name="l00550"></a>00550 <span class="comment"> * Set the motor speed control for the specified motor.</span>
<a name="l00551"></a>00551 <span class="comment"> *</span>
<a name="l00552"></a>00552 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00553"></a>00553 <span class="comment"> * @param constspeed use speed control to ensure motor speed stays constant under varying load</span>
<a name="l00554"></a>00554 <span class="comment"> */</span>
<a name="l00555"></a><a class="code" href="group__msmmux.html#ga0f61d2bd2faa6f654468c3bec21fc203">00555</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga0f61d2bd2faa6f654468c3bec21fc203">MSMMotorSetSpeedCtrl</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> constspeed) {
<a name="l00556"></a>00556   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#a201498569375a319530e44ca4bc069ff">pidcontrol</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = <span class="keyword">true</span>;
<a name="l00557"></a>00557 }
<a name="l00558"></a>00558 
<a name="l00559"></a>00559 <span class="comment"></span>
<a name="l00560"></a>00560 <span class="comment">/**</span>
<a name="l00561"></a>00561 <span class="comment"> * Set the ramping control for the specified motor.</span>
<a name="l00562"></a>00562 <span class="comment"> *</span>
<a name="l00563"></a>00563 <span class="comment"> * @param muxmotor the motor-MUX motor</span>
<a name="l00564"></a>00564 <span class="comment"> * @param ramping use ramping for starting and stopping the motor</span>
<a name="l00565"></a>00565 <span class="comment"> */</span>
<a name="l00566"></a><a class="code" href="group__msmmux.html#ga3415c02ea0ca9cf40c7585b8cb187a66">00566</a> <span class="keywordtype">void</span> <a class="code" href="group__msmmux.html#ga3415c02ea0ca9cf40c7585b8cb187a66">MSMMotorSetRamping</a>(<a class="code" href="group___m_m_u_x-common__h.html#ga11217de3dd0a7e4159c3578c1cdbba12">tMUXmotor</a> muxmotor, <span class="keywordtype">bool</span> ramping) {
<a name="l00567"></a>00567   <a class="code" href="group___m_m_u_x-common__h.html#ga048db86417be3a81da734debe91a52db">mmuxData</a>[<a class="code" href="group___m_m_u_x-common__h.html#gabf500b8c69e75f9fad47c3a3e25626c7">SPORT</a>(muxmotor)].<a class="code" href="structmmux_data_t.html#aaf32ec57dafc672cd270aeaceab02bdb">ramping</a>[<a class="code" href="group___m_m_u_x-common__h.html#ga9b28381cff35f11a5fd1aff7576117bc">MPORT</a>(muxmotor)] = (ramping) ? <a class="code" href="group__msmmux.html#gaaeea706af7bf946b39cd6edbaf1f0749">MSMMUX_RAMP_UP_DOWN</a> : <a class="code" href="group__msmmux.html#ga0d2f828e8c12510c8f5d1f794656bab0">MSMMUX_RAMP_NONE</a>;
<a name="l00568"></a>00568 }
<a name="l00569"></a>00569 
<a name="l00570"></a>00570 <span class="preprocessor">#endif //  __MSMMUX_H__</span>
<a name="l00571"></a>00571 <span class="preprocessor"></span>
<a name="l00572"></a>00572 <span class="comment">/*</span>
<a name="l00573"></a>00573 <span class="comment"> * $Id: mindsensors-motormux.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00574"></a>00574 <span class="comment"> */</span>
<a name="l00575"></a>00575 <span class="comment">/* @} */</span>
<a name="l00576"></a>00576 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:43 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
